package com.example.smartlearning.controller;

import com.example.smartlearning.service.impl.AnswerServiceImpl;
import com.example.smartlearning.service.impl.UserServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("/Smart/Answer/")
public class AnswerController {
    @Resource
    AnswerServiceImpl answerService;

    @Resource
    UserServiceImpl userService;

    /**
     * 根据标签查询问题
     *
     * @param tab   标签
     * @param start 开始
     * @param limit 限制
     * @return 返回
     */
    @GetMapping("selectAllByTab")
    public String selectAllByTab(@RequestParam("tab") String tab,
                                 @RequestParam("start") int start,
                                 @RequestParam("limit") int limit) {
        return answerService.selectAllByTab(tab, start, limit);
    }

    /**
     * 删除本问题
     *
     * @param answerId 问题id
     * @return 返回
     */
    @PostMapping("deleteAnswer")
    public String deleteAnswer(@RequestParam("answerId") int answerId) {
        return answerService.deleteAnswer(answerId);
    }

    /**
     * 用户加分
     *
     * @param userId 用户id
     * @param point  分数
     * @return 返回
     */
    @PostMapping("updateUserPointsAdd")
    public String updateUserPointsAdd(
            @RequestParam("userId") int userId,
            @RequestParam("points") int point
    ) {
        return userService.updateUserPointsAdd(userId, point);
    }
    /**
     * 用户扣分
     *
     * @param userId 用户id
     * @param point  分数
     * @return 返回
     */
    @PostMapping("updateUserPointsDelete")
    public String updateUserPointsDelete(
            @RequestParam("userId") int userId,
            @RequestParam("points") int point
    ) {
        return userService.updateUserPointsDelete(userId, point);
    }
}
